//
//  FeaturedViewController.m
//  TodatPlay
//
//  Created by dllo on 16/8/29.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "FeaturedViewController.h"
//Tool
#import "TAMacro.h"
#import "SelfSizeTool.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "MJRefresh.h"
// reuseableView
#import "FeatureCycleImageReusableView.h"
#import "TitleCollectionReusableView.h"

// cell
#import "FullImageCollectionViewCell.h"
#import "NestCollectionViewCell.h"
#import "HotCollectionViewCell.h"

// 第一部分model
#import "FirstTopimg.h"
#import "FeaturedFirstRootClass.h"
#import "FirstDatax.h"
#import "FirstData.h"
#import "CDMNetTool.h"
#import "Featured_model1_CollectionViewCell.h"
#import "Featured_model2_CollectionViewCell.h"
#import "Featured_model11_CollectionViewCell.h"
// 第二部分model
#import "FeaturedTwoRootClass.h"
#import "FeaturedTwoData.h"
#import "FeaturedTwoAdvlist.h"
#import "FeaturedTwoProjlist.h"
// 第三部分mdoel
#import "FeaturedThreeRootClass.h"
#import "FeaturedThreeData.h"

// VC
#import "DetailsViewController.h"
#import "WebViewViewController.h"
#import "EventsViewController.h"
#import "SearchViewController.h"
#import "InformationViewController.h"
#import "CityViewController.h"
// 宏
#define kFullImageCollecTionViewCellReuse @"FullImageReuse"
#define kNestColletionViewCellReuse @"NestReuse"
#define kHotColletionViewCellReuse @"HotReuse"
#define kCycleReusableViewReuse @"cycleReuse"
#define kTitleOfHeaderReuse @"titleReuse"
#define kModel1ColletionViewCellReuse @"mdoel1Reuse"
#define kModel2ColletionViewCellReuse @"mdoel2Reuse"
#define kModel11ColletionViewCellReuse @"mdoel11Reuse"
#define kHotDataForRow self.rootClassOfThree.data[indexPath.row]

@interface FeaturedViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *FeaturedCollectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *FeaturedViewLayout;
@property (nonatomic, strong) NSMutableArray *testCycleImage;
@property (nonatomic, strong) FeaturedFirstRootClass *rootClassOfFirst;
@property (nonatomic, strong) FeaturedTwoRootClass *rootClassOfTwo;
@property (nonatomic, strong) FeaturedThreeRootClass *rootClassOfThree;

@end

@implementation FeaturedViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self configCollectionView];
    [self handleDataFirst];
    [self handleDataSecond];
    [self handleDataThree];
    
}
#pragma mark -上啦刷新下拉加载
#pragma mark - 处理collectionView(注册和设置属性)
- (void)configCollectionView {
    // 关闭回弹效果
    self.FeaturedCollectionView.alwaysBounceVertical = YES;
    self.FeaturedCollectionView.bounces = NO;
    // init
    self.testCycleImage = [NSMutableArray array];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    self.FeaturedViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 5, 0);
    self.FeaturedViewLayout.minimumLineSpacing = 5;
    self.FeaturedViewLayout.minimumInteritemSpacing = 5;
    // 注册cell

    [self.FeaturedCollectionView registerNib:[UINib nibWithNibName:@"NestCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kNestColletionViewCellReuse];
    [self.FeaturedCollectionView registerNib:[UINib nibWithNibName:@"HotCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kHotColletionViewCellReuse];
    [self.FeaturedCollectionView registerNib:[UINib nibWithNibName:@"Featured_model1_CollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kModel1ColletionViewCellReuse];
    [self.FeaturedCollectionView registerNib:[UINib nibWithNibName:@"Featured_model2_CollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kModel2ColletionViewCellReuse];
    [self.FeaturedCollectionView registerNib:[UINib nibWithNibName:@"Featured_model11_CollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kModel11ColletionViewCellReuse];
    
    // 注册头部视图
    [self.FeaturedCollectionView registerClass:[FeatureCycleImageReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCycleReusableViewReuse];
    [self.FeaturedCollectionView registerClass:[TitleCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kTitleOfHeaderReuse];
   
    
    // 右侧两个按钮
    UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"index_search_white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(handleSearch:)];
    UIBarButtonItem *informationButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"nav_bar_msg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(handleInformation:)];
    
    self.navigationItem.rightBarButtonItems = @[searchButton, informationButton];
    // 左侧按钮
    NSString *title = @"北京市";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(handleCityButton:)];
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}
#pragma mark - 处理navigationBar上的按钮点击事件
- (void)handleSearch:(UIBarButtonItem *)btn {
    self.hidesBottomBarWhenPushed = YES;
    SearchViewController *searVC = [[SearchViewController alloc] init];
    [self.navigationController pushViewController:searVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
    
}
- (void)handleInformation:(UIBarButtonItem *)btn {
    self.hidesBottomBarWhenPushed = YES;
    InformationViewController *inforVC = [[InformationViewController alloc] init];
    [self.navigationController pushViewController:inforVC animated:YES];
    
    self.hidesBottomBarWhenPushed = NO;
}
- (void)handleCityButton:(UIBarButtonItem *)btn {
    self.hidesBottomBarWhenPushed = YES;
    CityViewController *cityVC = [[CityViewController alloc] init];
    [self.navigationController pushViewController:cityVC animated:YES];

    self.hidesBottomBarWhenPushed = NO;
}


#pragma mark - 处理数据
- (void)handleDataFirst {
      NSString *requestURLString = @"http://wanapi.damai.cn/getjingxuandatav2.json?cityid=500000&version=203004&useCash=false";
    [CDMNetTool  GET:requestURLString andBody:nil andHeader:nil andResponse:CDMJSON andSuccessBlock:^(id result) {
//        NSLog(@"成功%@", result);
        self.rootClassOfFirst = [FeaturedFirstRootClass modelWithDic:result];
        [self.FeaturedCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"失败%@", error);
    }];
}
- (void)handleDataSecond {
    NSString *requestURLString = @"http://wanapi.damai.cn/getAdvActivity.json?cityid=110000&version=203004";
    [CDMNetTool  GET:requestURLString andBody:nil andHeader:nil andResponse:CDMJSON andSuccessBlock:^(id result) {
//        NSLog(@"成功%@", result);
        
        self.rootClassOfTwo = [FeaturedTwoRootClass modelWithDic:result];
        // 刷新CollectionView
        [self.FeaturedCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"失败%@", error);
    }];

}
- (void)handleDataThree {
    NSString *requestURLString = @"http://wanapi.damai.cn/projlistnew.json?cateid=0&psize=20&cityid=110000&version=203004&pindex=0";
    [CDMNetTool  GET:requestURLString andBody:nil andHeader:nil andResponse:CDMJSON andSuccessBlock:^(id result) {
//        NSLog(@"成功%@", result);
        self.rootClassOfThree = [FeaturedThreeRootClass modelWithDic:result];
        // 刷新CollectionView
        [self.FeaturedCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"失败%@", error);
    }];
 
}
#pragma mark - CollectionView DataSource
#pragma mark - 分区数目
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return _rootClassOfFirst.data.count + _rootClassOfTwo.data.advList.count + 1;
}
#pragma mark - 每个分区的cell个数
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else if (section > 0 && section < self.rootClassOfFirst.data.count) {
        return 1;
    } else if (section >= self.rootClassOfFirst.data.count && section < (self.rootClassOfTwo.data.advList.count + self.rootClassOfFirst.data.count)){
        return 1;
    } else {
        return self.rootClassOfThree.data.count;
    }
}
#pragma mark - 返回自定义cell
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return nil;
    } else if (indexPath.section > 0 && indexPath.section < self.rootClassOfFirst.data.count) {
        if ([self.rootClassOfFirst.data[indexPath.section].typex isEqualToString:@"model1"]) {
            Featured_model1_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kModel1ColletionViewCellReuse forIndexPath:indexPath];
            NSURL *imageURL = [NSURL URLWithString:self.rootClassOfFirst.data[indexPath.section].datax.img];
            [cell.imageViewOfImg sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"project_bg_detail"]];
            /***************** 点击方法 ******************/
            [cell image:^(UITapGestureRecognizer *imageTap) {
                
                if ([self.rootClassOfFirst.data[indexPath.section].datax.typex isEqualToString:@"6"]) {
                     self.hidesBottomBarWhenPushed = YES;
                    WebViewViewController *webVC = [[WebViewViewController alloc] init];
                    webVC.webURLString = self.rootClassOfFirst.data[indexPath.section].datax.param;
                    [self.navigationController pushViewController:webVC animated:YES];
                     self.hidesBottomBarWhenPushed = NO;
                    
                } else if ([self.rootClassOfFirst.data[indexPath.section].datax.typex isEqualToString:@"1"]) {

                    DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
                    detailsVC.parm = self.rootClassOfFirst.data[indexPath.section].datax.param;
                    UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
                    detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
                    
                    [self presentViewController:detaNavi animated:YES completion:nil];
                } else {
                    self.hidesBottomBarWhenPushed = YES;
                    EventsViewController *eventVC = [[EventsViewController alloc] init];
                    eventVC.specialid = self.rootClassOfFirst.data[indexPath.section].datax.param;
                    [self.navigationController pushViewController:eventVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                }
                
            }];
            return cell;
        } else if ([self.rootClassOfFirst.data[indexPath.section].typex isEqualToString:@"model2"]) {
            Featured_model2_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kModel2ColletionViewCellReuse forIndexPath:indexPath];
            NSURL *leftImageURL = [NSURL URLWithString:self.rootClassOfFirst.data[indexPath.section].datax.leftimg];
            NSURL *rightImageURL = [NSURL URLWithString:self.rootClassOfFirst.data[indexPath.section].datax.rightimg];
            [cell.leftImageView sd_setImageWithURL:leftImageURL placeholderImage:[UIImage imageNamed:@"project_bg_detail"]];
            [cell.rightImageView sd_setImageWithURL:rightImageURL placeholderImage:[UIImage imageNamed:@"project_bg_detail"]];
            
            /***************** 左边右边的点击方法 ******************/
            [cell left:^(UITapGestureRecognizer *leftTap) {
                if ([self.rootClassOfFirst.data[indexPath.section].datax.lefttype isEqualToString:@"6"]) {
                    self.hidesBottomBarWhenPushed = YES;
                    WebViewViewController *webVC = [[WebViewViewController alloc] init];
                    webVC.webURLString = self.rootClassOfFirst.data[indexPath.section].datax.leftparm;
                    [self.navigationController pushViewController:webVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                } else if ([self.rootClassOfFirst.data[indexPath.section].datax.typex isEqualToString:@"1"]){
                    
                    DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
                    detailsVC.parm = self.rootClassOfFirst.data[indexPath.section].datax.leftparm;
                    UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
                    detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

                    [self presentViewController:detaNavi animated:YES completion:nil];
                } else {
                    self.hidesBottomBarWhenPushed = YES;
                    EventsViewController *eventVC = [[EventsViewController alloc] init];
                    eventVC.specialid = self.rootClassOfFirst.data[indexPath.section].datax.leftparm;
                    [self.navigationController pushViewController:eventVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                }
                
            } right:^(UITapGestureRecognizer *rightTap) {
                if ([self.rootClassOfFirst.data[indexPath.section].datax.righttype isEqualToString:@"6"]) {
                    self.hidesBottomBarWhenPushed = YES;
                    WebViewViewController *webVC = [[WebViewViewController alloc] init];
                    webVC.webURLString = self.rootClassOfFirst.data[indexPath.section].datax.rightparm;
                    [self.navigationController pushViewController:webVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                } else if ([self.rootClassOfFirst.data[indexPath.section].datax.typex isEqualToString:@"1"]) {
                    
                    DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
                    detailsVC.parm = self.rootClassOfFirst.data[indexPath.section].datax.rightparm;
                    UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
                    detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

                    [self presentViewController:detaNavi animated:YES completion:nil];
                } else {
                    self.hidesBottomBarWhenPushed = YES;
                    EventsViewController *eventVC = [[EventsViewController alloc] init];
                    eventVC.specialid = self.rootClassOfFirst.data[indexPath.section].datax.rightparm;
                    [self.navigationController pushViewController:eventVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                }
            }];
            
            return cell;
        } else {
            Featured_model11_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kModel11ColletionViewCellReuse forIndexPath:indexPath];
            NSURL *leftImageURL = [NSURL URLWithString:self.rootClassOfFirst.data[indexPath.section].datax.leftimg];
            NSURL *rightImageURL = [NSURL URLWithString:self.rootClassOfFirst.data[indexPath.section].datax.rightimg];
            [cell.leftImageView sd_setImageWithURL:leftImageURL placeholderImage:[UIImage imageNamed:@"project_bg_detail"]];
            [cell.rightImageView sd_setImageWithURL:rightImageURL placeholderImage:[UIImage imageNamed:@"project_bg_detail"]];
            /***************** 左边右边的点击方法 ******************/
            [cell left:^(UITapGestureRecognizer *leftTap) {
                if ([self.rootClassOfFirst.data[indexPath.section].datax.lefttype isEqualToString:@"6"]) {
                    self.hidesBottomBarWhenPushed = YES;
                    WebViewViewController *webVC = [[WebViewViewController alloc] init];
                    webVC.webURLString = self.rootClassOfFirst.data[indexPath.section].datax.leftparm;
                    [self.navigationController pushViewController:webVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                } else if ([self.rootClassOfFirst.data[indexPath.section].datax.typex isEqualToString:@"1"]) {
                    
                    DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
                    detailsVC.parm = self.rootClassOfFirst.data[indexPath.section].datax.leftparm;
                    UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
                    detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

                    [self presentViewController:detaNavi animated:YES completion:nil];
                } else {
                    self.hidesBottomBarWhenPushed = YES;
                    EventsViewController *eventVc = [[EventsViewController alloc] init];
                    eventVc.specialid = self.rootClassOfFirst.data[indexPath.section].datax.leftparm;
                    [self.navigationController pushViewController:eventVc animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                    
                }
                
            } right:^(UITapGestureRecognizer *rightTap) {
                if ([self.rootClassOfFirst.data[indexPath.section].datax.righttype isEqualToString:@"6"]) {
                    self.hidesBottomBarWhenPushed = YES;
                    WebViewViewController *webVC = [[WebViewViewController alloc] init];
                    webVC.webURLString = self.rootClassOfFirst.data[indexPath.section].datax.rightparm;
                    [self.navigationController pushViewController:webVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                } else if ([self.rootClassOfFirst.data[indexPath.section].datax.righttype isEqualToString:@"1"]) {

                    DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
                    detailsVC.parm = self.rootClassOfFirst.data[indexPath.section].datax.rightparm;
                    UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
                    detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

                    [self presentViewController:detaNavi animated:YES completion:nil];
                } else {
                    self.hidesBottomBarWhenPushed = YES;
                    EventsViewController *eventVC = [[EventsViewController alloc] init];
                    eventVC.specialid = self.rootClassOfFirst.data[indexPath.section].datax.rightparm;
                    [self.navigationController pushViewController:eventVC animated:YES];
                    self.hidesBottomBarWhenPushed = NO;
                }
            }];
            return cell;
        }
    } else if (indexPath.section >= self.rootClassOfFirst.data.count && indexPath.section < (self.rootClassOfTwo.data.advList.count + self.rootClassOfFirst.data.count)) {
        NestCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kNestColletionViewCellReuse forIndexPath:indexPath];
        cell.advList = self.rootClassOfTwo.data.advList[indexPath.section - self.rootClassOfFirst.data.count];
        /**================= 跳转方法 =====================*/

        [cell didSelectItemAtIndexPath:^(NSIndexPath *index) {

            DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
            detailsVC.parm = [NSString stringWithFormat:@"%@", self.rootClassOfTwo.data.advList[indexPath.section - self.rootClassOfFirst.data.count].projlist[index.row].ID];
            UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
            detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

            [self presentViewController:detaNavi animated:YES completion:nil];        }];
        
        return cell;
        
    } else {
        HotCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kHotColletionViewCellReuse forIndexPath:indexPath];
        NSURL *picURL = [NSURL URLWithString:self.rootClassOfThree.data[indexPath.row].pic];
        NSURL *orgavatarURL = [NSURL URLWithString:self.rootClassOfThree.data[indexPath.row].orgavatar];
       
        [cell.orgavatarImageView sd_setImageWithURL:orgavatarURL completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        }];
        [cell.picImageView sd_setImageWithURL:picURL placeholderImage:[UIImage imageNamed:@"project_bg_detail"]];
        /***************** 处理字符串数据(分割添加) ******************/
        NSString *pricestrlabel = kHotDataForRow.pricestr;
        if ([pricestrlabel containsString:@"-"]) {
            NSArray *arr = [pricestrlabel componentsSeparatedByString:@"-"];
            pricestrlabel = nil;
            pricestrlabel = [NSString stringWithFormat:@"%@起", arr.firstObject];
        } else if ([pricestrlabel containsString:@"元"]) {
            NSArray *arr = [pricestrlabel componentsSeparatedByString:@"元"];
            pricestrlabel = [NSString stringWithFormat:@"%@起", arr.firstObject];
        }
        // 处理字符串
        NSString *discountStr = kHotDataForRow.discount;
        if ([discountStr containsString:@"-"]) {
            NSArray *arr = [pricestrlabel componentsSeparatedByString:@"-"];
            discountStr = nil;
            discountStr = [NSString stringWithFormat:@"%@元", arr.firstObject];
        }
        // label字体加横线
        NSMutableAttributedString *newPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", discountStr]];
        [newPrice addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, newPrice.length)];
        
        /***************** 处理结束 ******************/
        cell.highlightsLabel.text = kHotDataForRow.highlights;
        cell.pricestrLabel.text = pricestrlabel;
        cell.discountLabel.attributedText = newPrice;
        cell.titleLabel.text = kHotDataForRow.title;
        cell.timestrLabel.text = kHotDataForRow.timestr;
        cell.addressLabel.text = kHotDataForRow.address;
        
        /**================= 跳转方法 =====================*/
        [cell cell:^(UITapGestureRecognizer *cellImageTap) {
            
            DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
            detailsVC.parm = [NSString stringWithFormat:@"%@", self.rootClassOfThree.data[indexPath.row].ID];

            UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailsVC];
            detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

            [self presentViewController:detaNavi animated:YES completion:nil];
            
        }];
        return cell;
    }
   
}
#pragma mark - 返回每个item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return CGSizeZero;
    } else if (indexPath.section > 0 && indexPath.section < self.rootClassOfFirst.data.count) {
        self.FeaturedViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 5, 0);
        self.FeaturedViewLayout.minimumLineSpacing = 5;
        self.FeaturedViewLayout.minimumInteritemSpacing = 5;
        if ([self.rootClassOfFirst.data[indexPath.section].typex isEqualToString:@"model11"]) {
            CGFloat width = SCREEN_WIDTH ;
            CGFloat height = 100;
            return CGSizeMake(width, height);
        } else if ([self.rootClassOfFirst.data[indexPath.section].typex isEqualToString:@"model1"]) {
            CGFloat width = SCREEN_WIDTH;
            CGFloat height = 130;
            
          return   CGSizeMake(width, height);
        } else {
            CGFloat width = SCREEN_WIDTH ;
            CGFloat height = SCREEN_WIDTH / 2.0;
           return  CGSizeMake(width, height);
        }
    } else if (indexPath.section >= self.rootClassOfFirst.data.count && indexPath.section < (self.rootClassOfTwo.data.advList.count + self.rootClassOfFirst.data.count)) {
        self.FeaturedViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 5, 0);
        self.FeaturedViewLayout.minimumLineSpacing = 5;
        self.FeaturedViewLayout.minimumInteritemSpacing = 5;
        return CGSizeMake(SCREEN_WIDTH, 250);
    } else {
        self.FeaturedViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.FeaturedViewLayout.minimumLineSpacing = 0;
        self.FeaturedViewLayout.minimumInteritemSpacing = 0;
        CGFloat addHeight = [SelfSizeTool selfSizeHeightWithString:kHotDataForRow.title width:SCREEN_WIDTH font:[UIFont systemFontOfSize:15]];
        return CGSizeMake(SCREEN_WIDTH, 350 + addHeight);
    }
}
#pragma mark - 返回每个分区头视图的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 230);
    } else if (section > 0 && section < self.rootClassOfFirst.data.count){
        if (self.rootClassOfFirst.data[section].datax.disname) {
            return CGSizeMake(0, 50);
        } else {
            return CGSizeZero;
        }
    } else {
        return CGSizeMake(0, 40);
    }
}
#pragma mark - 返回头视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
   if (indexPath.section == 0) {
       FeatureCycleImageReusableView *cycleReuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCycleReusableViewReuse forIndexPath:indexPath];
       // 处理网络图片数组(将topimg数组传到轮播图数组中)
        cycleReuseable.cycleImageView.topimg = self.rootClassOfFirst.data[indexPath.section].datax.topimg.mutableCopy;
       // 通过block实现轮播图的点击方法
       
       [cycleReuseable.cycleImageView didSelectItemAtIndexPath:^(NSIndexPath *index) {
           if (index.row > 0 && index.row <= self.rootClassOfFirst.data[indexPath.section].datax.topimg.count) {
               if ([self.rootClassOfFirst.data[indexPath.section].datax.topimg[index.row - 1].typex isEqualToString:@"6"]) {
                   self.hidesBottomBarWhenPushed = YES;
                   WebViewViewController *webVC = [[WebViewViewController alloc] init];
                   webVC.webURLString = self.rootClassOfFirst.data[indexPath.section].datax.topimg[index.row - 1].parm;
                   [self.navigationController pushViewController:webVC animated:YES];
                   self.hidesBottomBarWhenPushed = NO;
               } else if ([self.rootClassOfFirst.data[indexPath.section].datax.topimg[index.row - 1].typex isEqualToString:@"1"]){
                   
                   DetailsViewController *detailVC = [[DetailsViewController alloc] init];
                   detailVC.parm =  self.rootClassOfFirst.data[indexPath.section].datax.topimg[index.row - 1].parm;
                   UINavigationController *detaNavi = [[UINavigationController alloc] initWithRootViewController:detailVC];
                   detaNavi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

                   [self presentViewController:detaNavi animated:YES completion:nil];
               } else {
                   self.hidesBottomBarWhenPushed = YES;
                   EventsViewController *eventsVC = [[EventsViewController alloc] init];
                   eventsVC.specialid = self.rootClassOfFirst.data[indexPath.section].datax.topimg[index.row - 1].parm;
                   [self.navigationController pushViewController:eventsVC animated:YES];
                   self.hidesBottomBarWhenPushed = NO;
               }

           }
        }];
       return cycleReuseable;
    } else if (indexPath.section > 0 && indexPath.section < self.rootClassOfFirst.data.count) {
        TitleCollectionReusableView *titleReuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kTitleOfHeaderReuse forIndexPath:indexPath];
        
        titleReuseable.labelTitle.text = self.rootClassOfFirst.data[indexPath.section].datax.modelname;
        titleReuseable.backgroundColor = [UIColor whiteColor];
        return titleReuseable;
    } else if (indexPath.section >= self.rootClassOfFirst.data.count && indexPath.section < (self.rootClassOfTwo.data.advList.count + self.rootClassOfFirst.data.count)) {
        TitleCollectionReusableView *titleReuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kTitleOfHeaderReuse forIndexPath:indexPath];
        titleReuseable.labelTitle.text = self.rootClassOfTwo.data.advList[indexPath.section - self.rootClassOfFirst.data.count].avdtitle;
        titleReuseable.backgroundColor = [UIColor whiteColor];
        return titleReuseable;

    } else {
        TitleCollectionReusableView *titleReuseable = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kTitleOfHeaderReuse forIndexPath:indexPath];
        
        titleReuseable.labelTitle.text = @"热门推荐";
        titleReuseable.backgroundColor = [UIColor whiteColor];
        return titleReuseable;

    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
